<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>常见问题</title>
		<link rel="stylesheet" href="../../css/simple-line-icons.css">
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/mui-ext.css">
		
		<style>
			#dv-pro-title p{
				overflow: hidden; 
				text-overflow: ellipsis; 
				display: -webkit-box; 
				-webkit-line-clamp: 3; 
				-webkit-box-orient: vertical;
			}
			
			*{
				padding: 0px;
				border: 0px;
				margin: 0px;
				font-family: "黑体";
			}
		</style>
	</head>
	<body style="background-color: white;">
	
		<div class="mui-content" style="margin: 10px 5px 5px 5px; background-color: white;">
			<div style="margin-left: 10px; margin-right: 10px;">
				<div id="dv-pro-title" style="display: flex;">
					<!--<span id="proImg"></span>-->
					<div style="margin-left: 0px;">
						<span id="proTitle" style="color: #303030; font-size: 16px;"></span>
						<span id="proContentAbstract" style="font-size: 15px; color: #909090; display: block;"></span>
					</div>
				</div>	
				<div style="margin-top: 5px;">
					<hr style="width: 100%; height: 1px; background-color: #dcdcdc;" />
				</div>
				<div id="dv-pro-content" style="margin-top: 10px; font-size: 15px; color: #909090;text-align: justify; text-justify: inter-ideograph;">
						
				</div>
			</div>
			<div style="margin-top: 5px;">
				<hr style="width: 100%; height: 1px; background-color: #dcdcdc;" />
			</div>
			<div id="dvProCommlst" style="margin-bottom: 40px;">
				
			</div>
			<div style="margin-top: 20px;"></div>
		</div>
		<nav class="mui-bar mui-bar-tab">
			<form class="mui-input-group" style="padding: 5px;">
				<div class="mui-row">
					<div class="mui-col-xs-10">
						<input type="text" placeholder="说说..." id="iptComm">
					</div>
					<div class="mui-col-xs-2">
						<button id="btnAddProComm" type="button" class="mui-btn mui-btn-default" style="min-width:40px;top:2px;" onclick="return false;">评论</button>
					</div>
				</div>
			</form>			
		</nav>
			
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/utils/http.utils.js"></script>
		<script src="../../js/bus/pubfun.js"></script>
		<script>
			var $wxfwid = localStorage.getItem("wxfwid");
			var $currUser = JSON.parse(localStorage.getItem("login-user-parent"));
			var $comProId = getQueryString(window.location.search, "proid");
			//fun_getUrlForParams(window.location.href, "proid");
			
			window.onload = function(){
				fun_loadComProDetailed();
				fun_loadCommLst();
			}
			
			function fun_loadComProDetailed(){
				mui.ajax({
					url : $request_url.getComProInfo,
					type: "post",
					headers: {
						"Authorization": $headers_authorization
					},
					data: {
						id: $comProId
					},
					dataType: "json",
					success: function(dat) {
						if(dat.code == 0){
							document.title = dat.result.title;
							//document.getElementById("proImg").innerHTML = '<img src="'+ dat.result.thumbnail +'" height="90" width="90" style="-moz-border-radius: 15px; -webkit-border-radius: 15px; border-radius:15px;" />';
							document.getElementById("proTitle").innerHTML = dat.result.title;
							//document.getElementById("proContentAbstract").innerHTML = dat.result.contentAbstract;
							document.getElementById("dv-pro-content").innerHTML = dat.result.content;
						} else {
							mui.toast("无数据源...")
						}
					}, error : function(err){
						mui.toast("服务繁忙...");
					}
				});
			}
			
			document.getElementById("btnAddProComm").addEventListener("tap", function(){
				if($currUser == null || $currUser == ""){
					mui.toast("尚未登录，无法评论");
					return;
				}
				
				var $comm = document.getElementById("iptComm").value;
				if($comm == null || $comm == ""){
					mui.toast("请输入评论内容");
					return;
				}
				
				mui.ajax({
					url : $request_url.addProblemComm,
					type: "post",
					headers: {
						"Authorization": $headers_authorization
					},
					data: {
						userId: $currUser.userId,
						objectType : "article",
						destObjectId : $comProId,
						commentContent : $comm
					},
					dataType: "json",
					success: function(dat) {
						if(dat.code == 0){
							var $commHtmls = document.getElementById("dvProCommlst");
							var $dvComm = document.createElement("div");
							$dvComm.innerHTML = fun_commentHtml(dat.result);
							$commHtmls.appendChild($dvComm);
							document.getElementById("iptComm").value = "";
						} else {
							mui.toast(dat.message);
							return;
						}
					}, error : function(err){
						mui.toast("服务繁忙...");
						return;
					}
				});
				
			});
			
			function fun_commentHtml($comm){
				var $nickName = "";
				if($comm.commentUser.nickName == null || $comm.commentUser.nickName == ""){
					$nickName = "无名氏";
				} else {
					$nickName = $comm.commentUser.nickName;
				}
				//../../img/icon/zhuanjia.png
				var $commHtml = 
				'<div style="display: flex; width: 100%; margin: 5px 0px 15px 0px;">'
				+	'<div style="float: left; width: 20%;">'
				+		'<img src="' + $comm.commentUser.faceImage + '" height="40" width="40" style="-moz-border-radius: 15px; -webkit-border-radius: 15px; border-radius:15px;" />'
				+	'</div>'
				+	'<div style="width: 60%;">'
				+		'<span style="font-size: 16px; color: #303030;">'+ $nickName +'</span>'
				+		'<span style="display: block; font-size: 15px; color: #909090; margin: 20px 0px 0px 0px;">'+ $comm.content +'</span>'
				+	'</div>'
				+	'<div style="float: right; width: 20%; margin: auto 0px auto 0px;">'
				+		'<span style="font-size: 15px; color: #909090;">'+ $comm.commentTimeDiff +'</span>'
				+	'</div>'
				+'</div>'
				+'<hr />';
				return $commHtml;
			}
			
			
			function fun_commentLstHtml($comm, $num){
				var $nickName = "";
				if($comm.commentUser.nickName == null || $comm.commentUser.nickName == ""){
					$nickName = "无名氏";
				} else {
					$nickName = $comm.commentUser.nickName;
				}
				//../../img/icon/zhuanjia.png
				var $commHtml = 
				'<div style="display: flex; width: 100%; margin: 5px 0px 15px 0px;">'
				+	'<div style="float: left; width: 20%;">'
				+		'<img src="' + $comm.commentUser.faceImage + '" height="40" width="40" style="-moz-border-radius: 15px; -webkit-border-radius: 15px; border-radius:15px;" />'
				+	'</div>'
				+	'<div style="width: 50%;">'
				+		'<span style="font-size: 16px; color: #303030;">'+ $nickName +'</span>'
				+		'<span style="display: block; font-size: 15px; color: #909090; margin: 20px 0px 0px 0px;">'+ $comm.content +'</span>'
				+	'</div>'
				+	'<div style="float: right; width: 30%; margin: auto 0px auto 0px;">'
				+		'<span style="font-size: 13px; color: #909090;">'+ $comm.commentTimeDiff +'</span>'
				+	'</div>'
				+'</div>'
				+'<hr />';
				return $commHtml;
			}
			
			function fun_loadCommLst(){
				mui.ajax({
					url : $request_url.getProblemList,
					type : "get",
					dataType : "json",
					headers: {
					"Authorization": $headers_authorization
					},
					data : {
						orgId : $wxfwid,
						objectType : "article",
						destObjectId : $comProId,
						rows : 10,
						page : 0
					},
					success : function(dat){
						if(dat.code == 0){
							var $artCommLst = document.getElementById("dvProCommlst");
							var $commArr = dat.result;
							if($commArr != null && $commArr != ""){
								for(var i = 0; i < $commArr.length; i ++){
									var $commDoc = document.createElement("div");
									$commDoc.innerHTML = fun_commentLstHtml($commArr[i], i);
									$artCommLst.appendChild($commDoc);
								}
							}
						} else {
							mui.toast(dat.message);
						}
						
					}, error : function(err){
						mui.toast("无评论数据...");
					}
				});
			}
		</script>
	</body>

</html>